﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using BoekenUsb2.Model;

namespace BoekenUsb2.Model.DatabaseRepositories
{
    public abstract partial class DatabaseRepository
    {
        protected IDBManager dbManager;

        public DatabaseRepository()
        {
        }

        public DataTable defaultExecuteReaderDataTable(CommandType commandType, string commandText)
        {
            DataTable dt = new DataTable();
            try
            {
                dbManager.Open();
                dbManager.ExecuteReader(commandType, commandText);
                dt.Load(dbManager.DataReader);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
            return dt;
        }

        public void defaultExecuteNonQuery(CommandType commandType, string commandText)
        {
            try
            {
                dbManager.Open();
                dbManager.ExecuteNonQuery(commandType, commandText);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}